package com.gome.spiderkit.task.monitor;

import java.io.IOException;
import java.util.Date;
import java.util.concurrent.TimeoutException;

import org.apache.log4j.Logger;
import org.quartz.Job;
import org.quartz.JobDetail;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import com.gome.spiderkit.data.SpiderkitInfoConnection;
import com.gome.spiderkit.model.GroupSummary;
import com.gome.spiderkit.task.base.ScheduJobConfig;

public class MonitorJob extends ScheduJobConfig implements Job {
	static private String name = "monitor-job";
	static private String group = "cron";
	SpiderkitInfoConnection skinfoClient = new SpiderkitInfoConnection();
	
	public MonitorJob() {
		this.setJobName(name);
		this.setJobGroup(group);
	}
	
	public void connect(String zkhost) throws IOException, InterruptedException, TimeoutException {
			skinfoClient.connect(zkhost);
	}

	public void execute(JobExecutionContext jobCtx) throws JobExecutionException {

		try {
			skinfoClient.updateFromServer();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return;
		}
		
		System.out.println("update info!");
		
		GroupSummary gsummary = skinfoClient.getGroupSummary();
	}

	public void close() {
		skinfoClient.close();
	}
	
	public JobDetail getJob() {
		return this.getJobBuilder(MonitorJob.class).build();
	}
}
